package common.config.exception;

import cn.hutool.core.exceptions.ExceptionUtil;
import common.config.http.HttpStatusEnum;
import lombok.Getter;
import lombok.Setter;

/**
 * 自定义异常
 *
 * @author 米泽鹏
 * @since 2021-07-08 下午 7:16
 */
@Getter
@Setter
public class CustomException extends RuntimeException {

	private static final long serialVersionUID = 1L;

	/**
	 * 错误码
	 */
	protected Integer code;

	public CustomException() {
		super(HttpStatusEnum.INTERNAL_SERVER_ERROR.getMessage());
		this.code = HttpStatusEnum.INTERNAL_SERVER_ERROR.getCode();
	}

	public CustomException(Throwable cause) {
		super(ExceptionUtil.getSimpleMessage(cause), cause);
		this.code = HttpStatusEnum.INTERNAL_SERVER_ERROR.getCode();
	}

	public CustomException(BaseErrorInfoInterface errorInfoInterface) {
		super(errorInfoInterface.getMessage());
		this.code = errorInfoInterface.getCode();
	}

	public CustomException(BaseErrorInfoInterface errorInfoInterface, Throwable cause) {
		super(errorInfoInterface.getMessage(), cause);
		this.code = errorInfoInterface.getCode();
	}

	public CustomException(String message) {
		super(message);
		this.code = HttpStatusEnum.INTERNAL_SERVER_ERROR.getCode();
	}

	public CustomException(Integer code, String message) {
		super(message);
		this.code = code;
	}

	public CustomException(Integer code, String message, Throwable cause) {
		super(message, cause);
		this.code = code;
	}

//  /**
//   * 取消爬栈提升效率
//   */
//  @Override
//  public Throwable fillInStackTrace() {
//    return this;
//  }

}
